package cn.jzq.spring.springioc.demo;

import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @author jzq
 * @date 2019/3/20 13:35
 */
@Service
public class UserServiceImpl implements UserService {

    public Set<User> users = new HashSet<>();
    private final UserMapper userMapper;

    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public User getUserById(Integer userId) {
        return userMapper.getUserById(userId);
    }

    @Override
    public void saveUser(User user) {
        users.add(user);
    }

    @Override
    public void deleteUser(Integer id) {
        users.removeIf(u -> Objects.equals(u.getId(), id));
    }

    @Override
    public Set<User> listUser() {
        return users;
    }
}
